using System.Collections.Generic;

namespace OracleInternal.SqlAndPlsqlParser
{
	internal class StreamableSet<T> : Set<T>, IStreamable where T : IStreamable, new()
	{
		public int ReadFromStream(InputStream istrm)
		{
			if (istrm.ReadLine() == GetType().Name)
			{
				istrm.ReadLine();
				int num = int.Parse(istrm.ReadLine());
				for (int i = 0; i < num; i++)
				{
					T item = new T();
					item.ReadFromStream(istrm);
					Add(item);
				}
				return 0;
			}
			return -1;
		}

		public int WriteToStream(OutputStream ostrm)
		{
			ostrm.WriteLine(GetType().Name);
			ostrm.WriteLine(typeof(T).Name);
			ostrm.WriteLine(base.Count.ToString());
			using (Enumerator enumerator = GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					enumerator.Current.WriteToStream(ostrm);
				}
			}
			ostrm.Flush();
			return 0;
		}

		public StreamableList<T> GetList()
		{
			return new StreamableList<T>(this);
		}
	}
}
